<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            *{
                text-align: center;
            }
            .center {
                margin: auto;
                width: 26%;
            }
            a{
                color: black;
                text-decoration: none;
            }
            a:hover{
                color: black;
                text-decoration: none;
            }
        </style>
        <script th:src="@{/jquery-1.8.3.min.js}"></script>
    </head>
    <body>
        <div class="center">
            <form action="/book/doAdd" method="post" enctype="multipart/form-data" onsubmit="return fk()">
                <table border="1">
                    <tr>
                        <td colspan="2">
                            <h4>添加书籍信息</h4>
                        </td>
                    </tr>
                    <tr>
                        <th>书名</th>
                        <td>
                            <input type="text" th:name="name" id="name"/>
                        </td>
                    </tr>
                    <tr>
                        <th>价格</th>
                        <td>
                            <input type="text" th:name="price" id="price"/>
                        </td>
                    </tr>
                    <tr>
                        <th>类目</th>
                        <td>
                            <input type="text" th:name="category" id="category"/>
                        </td>
                    </tr>
                    <tr>
                        <th>库存</th>
                        <td>
                            <input type="text" th:name="pnum" id="pnum"/>
                        </td>
                    </tr>
                    <tr>
                        <th>图片</th>
                        <td>
                            <input type="file" th:name="img" id="imgurl"/>
                        </td>
                    </tr>
                    <tr>
                        <th>说明</th>
                        <td>
                            <input type="text" th:name="description" id="description"/>
                        </td>
                    </tr>
                    <tr>
                        <th>作者</th>
                        <td>
                            <input type="text" th:name="author" id="author"/>
                        </td>
                    </tr>
                    <tr>
                        <th>已售</th>
                        <td>
                            <input type="text" th:name="sales" id="sales"/>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <input type="submit" value="新增"/>
                            <a th:href="@{/book/getAll}">
                                <input type="button" value="返回"/>
                            </a>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
    <script>
        function fk(){
            if(document.getElementById("name").value == ''){
                alert("请填写书名!");
                return false;
            }
            if(document.getElementById("price").value == ''){
                alert("请填写价格!");
                return false;
            }
            if(document.getElementById("category").value == ''){
                alert("请填写类目!");
                return false;
            }
            if(document.getElementById("pnum").value == ''){
                alert("请填写库存!");
                return false;
            }
            if(document.getElementById("imgurl").value == ''){
                alert("请选择图片!");
                return false;
            }
            if(document.getElementById("description").value == ''){
                alert("请填写说明!");
                return false;
            }
            if(document.getElementById("author").value == ''){
                alert("请填写作者!");
                return false;
            }
            if(document.getElementById("sales").value == ''){
                alert("请填写已售!");
                return false;
            }
            return true
        }
    </script>
</html>